#
#copyright (C) 2017-2030 TW
#
#by gmzhuo@TW@18:02-2018-01-15.
#

MODULE = easycwmp-1.6.0

RELATIVE_PATH = $(subst $(MUDP_TOP_DIR)/,,$(shell pwd))

.PHONY: all prepare menuconfig build install rootfs clean 

ifeq ($(MODULE),xxx-0.0.0)
all: 
	@echo $(MODULE) is templete module.
else
ifneq ($(shell find ./ -mmin -$(MUDP_INTERVAL_COMPILE_TIME) -mmin +0 -cmin -$(MUDP_INTERVAL_COMPILE_TIME) -cmin +0),)
all: clean prepare build install rootfs
	@echo building of $(MODULE) is complete.
else
all: 
	@echo nothing to do with building of $(MODULE).
endif
endif

prepare:
	$(shell [ -d $(MUDP_BUILD_DIR)/$(RELATIVE_PATH) ] || mkdir -p $(MUDP_BUILD_DIR)/$(RELATIVE_PATH))
	tar -xzvf $(MODULE).tar.gz -C  $(MUDP_BUILD_DIR)/$(RELATIVE_PATH)
	cp files/* $(MUDP_BUILD_DIR)/$(RELATIVE_PATH)/$(MODULE)/ -rfd
	cd $(MUDP_BUILD_DIR)/$(RELATIVE_PATH)/$(MODULE); \
			autoreconf -i; \
			./configure CC=$(CC) CFLAGS=-I$(MUDP_INSTALL_DIR)/include LDFLAGS="$(LDFLAGS) -L$(MUDP_INSTALL_DIR)/lib -ljson-c " --prefix=$(MUDP_INSTALL_DIR) --host=$(TARGET) \
						LIBCURL_CFLAGS=-I$(MUDP_INSTALL_DIR)/include  LIBCURL_LIBS="-L$(MUDP_INSTALL_DIR)/lib/ -lcurl" \
						MICROXML_CFLAGS=-I$(MUDP_INSTALL_DIR)/include MICROXML_LIBS="-L$(MUDP_INSTALL_DIR)/lib -lmicroxml"\

menuconfig:
	echo nothing to do.

build:
	make -C $(MUDP_BUILD_DIR)/$(RELATIVE_PATH)/$(MODULE) 

install:
	make -C $(MUDP_BUILD_DIR)/$(RELATIVE_PATH)/$(MODULE) INSTROOT=$(MUDP_INSTALL_DIR)  install
	cp -rf ./rootfs/. $(MUDP_INSTALL_DIR)

rootfs:
	cp -rf $(MUDP_INSTALL_DIR)/bin/easycwmpd $(MUDP_ROOTFS_DIR)/bin
	cp -rf ./rootfs/. $(MUDP_ROOTFS_DIR)
	
clean:
	rm -rf $(MUDP_BUILD_DIR)/$(RELATIVE_PATH)/$(MODULE)

